﻿using System.ServiceModel;
using Microsoft.TeamFoundation;

namespace TfsRollUp.Core
{
    /// <summary>
    /// Management interface for the plugin/service
    /// </summary>
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    public class Manager : IManager
    {
        private Service _service;

        /// <summary>
        /// ctor
        /// </summary>
        public Manager(Service service)
        {
            _service = service;
        }

        /// <summary>
        /// Enable or disable rollup processing
        /// </summary>
        /// <param name="enableProcessing"></param>
        public void EnableRollUpProcessing(bool enableProcessing)
        {
            TeamFoundationTrace.MethodEntry(new object[] { enableProcessing });
            TeamFoundationTrace.Info("{0}.EnableRollUpProcessing: Processing set to {0}", enableProcessing);
            _service.Settings.EnableRollUpProcesing = enableProcessing;
            TeamFoundationTrace.MethodExit();
        }

        /// <summary>
        /// Enable or disable the saving of calculation result information in this workitem
        /// </summary>
        /// <param name="workItemId"></param>
        /// <param name="enable"></param>
        /// <returns>Number of workitems under monitoring</returns>
        public int MonitorWorkItem(int workItemId, bool enable)
        {
            TeamFoundationTrace.MethodEntry(new object[] { workItemId, enable });
            TeamFoundationTrace.Info("{0}.MonitorWorkItem: Monitoring workitem:{0}:{1}", workItemId, enable);
            int numberOfWorkItemsUnderMonitoring = _service.Settings.AddWorkItemToMonitorList(workItemId, enable);
            TeamFoundationTrace.MethodExit();
            return numberOfWorkItemsUnderMonitoring;
        }
    }
}
